% calc shape directly from gravity acceleration (Lindal 1985, Eqs. 2-8
clear all
close all

set(gcf,'Position',[1500 5000 [1200 1000]]);
fs=17;
fac1=1;
set(gcf,'PaperPositionMode','auto');
set(0,'DefaultAxesFontSize',fac1*fs)
set(0,'DefaultTextFontSize',fac1*fs)
set(0,'DefaultLineLinewidth',fac1*3)

occ_size=12;

load Shape_Jupiter_results_optimal.mat

lat=-90:0.5:90;

lat_s=-90:0.025:90;

subplot(3,2,1)
hold on
h(1)=plot(lat,U_obs,'Color',0*[1 1 1],'LineWidth',5);
h(2)=plot(lat,U_sol_100mb_grav,'Color','b','LineWidth',3);
h(3)=plot(lat,U_sol_100mb,'Color',[0.3 0.6 0],'LineWidth',3);
title (['Jupiter']);% (' num2str(cases) ' cases)'])
ylabel '{\itU} (m s^{-1})'
%xlabel Latitude
axis([-90 90 -100 160])
grid
set(gca,'XTick',-60:30:60)
box on
legend(h,'Observed','Optimal (Grav+Occ)','Optimal (Occ only)','Location','northwest','Fontsize',12)
text(0,1.06,'(a)','Units','normalized','FontWeight','bold','FontSize',fac1*fs*1.1)


subplot(3,2,3)
hold on
plot(lat,h_winds_obs_100mb(1,:)/1e3,'Color','k','LineWidth',3);
plot(lat_s,1e-3*(shape_all_100mb_grav(:,end)-shape_static_all_100mb_grav(:,end)),'Color','b','LineWidth',3);
%h(3)=errorbar(Occ_J_res_100mb(:,1),Occ_J_res_100mb(:,2),5*ones(6,1),'or','vertical','MarkerSize',7,'MarkerFaceColor','r','LineWidth',2);
h(1)=errorbar(Occ_J_sol_100mb_grav(:,1),Occ_J_sol_100mb_grav(:,2),5*ones(length(Occ_J_sol_100mb_grav),1),'ok','vertical','MarkerSize',occ_size,'MarkerFaceColor','r','LineWidth',2);
%h(4)=plot(Occ_J_sol_100mb(:,1),Occ_J_sol_100mb(:,2),'o','Color',[0.3 0.6 0],'MarkerSize',10,'MarkerFaceColor','none','LineWidth',3);
axis([-90 90 -20 20])
text(0,1.06,'(c)','Units','normalized','FontWeight','bold','FontSize',fac1*fs*1.1)
grid
%title 'Jupiter'
ylabel 'Dynamical height (km)'
set(gca,'XTick',-60:30:60)
box on
title ('Gravity + Occultations optimized','FontWeight','normal')
%legend(h,'Wind (Obs.) induced','Wind (Opt.) induced','Occultations (R_p=66,896km)','occultations (R_p=66,897km)','Location','southeast','Fontsize',10)

subplot(3,2,5)
hold on
plot(lat,h_winds_obs_100mb(1,:)/1e3,'Color','k','LineWidth',3);
plot(lat_s,1e-3*(shape_all_100mb(:,end)-shape_static_all_100mb(:,end)),'Color',[0.3 0.6 0],'LineWidth',3);
%h(3)=errorbar(Occ_J_res_100mb(:,1),Occ_J_res_100mb(:,2),5*ones(6,1),'or','vertical','MarkerSize',7,'MarkerFaceColor','r','LineWidth',2);
h(1)=errorbar(Occ_J_res_100mb(:,1),Occ_J_res_100mb(:,2),5*ones(length(Occ_J_res_100mb),1),'ok','vertical','MarkerSize',occ_size,'MarkerFaceColor','r','LineWidth',2);
%h(4)=plot(Occ_J_sol_100mb(:,1),Occ_J_sol_100mb(:,2),'o','Color',[0.3 0.6 0],'MarkerSize',10,'MarkerFaceColor','none','LineWidth',3);
axis([-90 90 -20 20])
text(0,1.06,'(e)','Units','normalized','FontWeight','bold','FontSize',fac1*fs*1.1)
grid
%title 'Jupiter'
ylabel 'Dynamical height (km)'
xlabel 'Latitude'
set(gca,'XTick',-60:30:60)
box on
title ('Occultations only optimized','FontWeight','normal')
%legend(h,'Wind (Obs.) induced','Wind (Opt.) induced','Occultations (R_p=66,896km)','occultations (R_p=66,897km)','Location','southeast','Fontsize',10)

%% Saturn

load Shape_Saturn_results_optimal.mat


clear h
subplot(3,2,2)
hold on
h(1)=plot(lat,U_obs_S,'Color',0*[1 1 1],'LineWidth',5);
h(2)=plot(lat,U_sol_100mb_grav,'b','LineWidth',3);
h(3)=plot(lat,U_sol_100mb,'Color',[0.3 0.6 0],'LineWidth',3);
%h(4)=plot(lat,U_sol_1bar,'Color',[0.3 0.6 0],'LineWidth',3);
title (['Saturn']);% (' num2str(cases) ' cases)'])
%ylabel '{\itU} (m s^{-1})'
%xlabel Latitude
axis([-90 90 -160 320])
text(0,1.06,'(b)','Units','normalized','FontWeight','bold','FontSize',fac1*fs*1.1)
grid
set(gca,'XTick',-60:30:60)
box on
legend(h,'Observed','Optimal (Grav+Occ)','Optimal (Occ only)','Location','northwest','Fontsize',12,'Color','None')


subplot(3,2,4)
hold on
h(1)=plot(lat,h_winds_obs_100mb(2,:)/1e3,'Color','k','LineWidth',3);
h(2)=plot(lat_s,1e-3*(shape_all_100mb_grav(:,end)-shape_static_all_100mb_grav(:,end)),'Color','b','LineWidth',3);
%h(3)=errorbar(Occ_S_res_100mb(:,1),Occ_S_res_100mb(:,2),5*ones(5,1),'or','vertical','MarkerSize',7,'MarkerFaceColor','r','LineWidth',2);
h(1)=errorbar(Occ_S_sol_100mb_grav(:,1),Occ_S_sol_100mb_grav(:,2),5*ones(length(Occ_S_sol_100mb_grav),1),'ok','vertical','MarkerSize',occ_size,'MarkerFaceColor','r','LineWidth',2);
%h(4)=plot(Occ_S_sol_100mb(:,1),Occ_S_sol_100mb(:,2),'o','Color',[0.3 0.6 0],'MarkerSize',10,'MarkerFaceColor','none','LineWidth',3);
axis([-90 90 -20 50])
text(0,1.06,'(d)','Units','normalized','FontWeight','bold','FontSize',fac1*fs*1.1)
grid
xlabel 'Latitude'
set(gca,'XTick',-60:30:60)
box on
title ('Gravity + Occultations optimized','FontWeight','normal')
%legend(h,'Wind (Grav. Opt.) induced','Wind (Opt.) induced','Occultations (R_p=54,438km)','occultations (R_p=54,436km)','Location','northeast','Fontsize',10)


subplot(3,2,6)
hold on
h(1)=plot(lat,h_winds_obs_100mb(2,:)/1e3,'Color','k','LineWidth',3);
h(2)=plot(lat_s,1e-3*(shape_all_100mb(:,end)-shape_static_all_100mb(:,end)),'Color',[0.3 0.6 0],'LineWidth',3);
%h(3)=errorbar(Occ_S_res_100mb(:,1),Occ_S_res_100mb(:,2),5*ones(5,1),'or','vertical','MarkerSize',7,'MarkerFaceColor','r','LineWidth',2);
h(1)=errorbar(Occ_S_res_100mb(:,1),Occ_S_res_100mb(:,2),5*ones(length(Occ_S_res_100mb),1),'ok','vertical','MarkerSize',occ_size,'MarkerFaceColor','r','LineWidth',2);
%h(4)=plot(Occ_S_sol_100mb(:,1),Occ_S_sol_100mb(:,2),'o','Color',[0.3 0.6 0],'MarkerSize',10,'MarkerFaceColor','none','LineWidth',3);
axis([-90 90 -20 50])
text(0,1.06,'(f)','Units','normalized','FontWeight','bold','FontSize',fac1*fs*1.1)
grid
xlabel 'Latitude'
set(gca,'XTick',-60:30:60)
box on
title ('Occultations only optimized','FontWeight','normal')
%legend(h,'Wind (Grav. Opt.) induced','Wind (Opt.) induced','Occultations (R_p=54,438km)','occultations (R_p=54,436km)','Location','northeast','Fontsize',10)




return
